<?php
namespace app\controller\api\v1\housing;

use app\Request;
use app\validate\api\housing\HousingFeedbackSuggestionValidate;
use think\facade\Db;

class HousingFeedbackSuggestion
{


	public function feedbacksuggestion_add (Request $request)
	{
		[$module, $types, $suggestion, $suggestion_img] = $request->postMore ([['module',''],['types',''],['suggestion',''],['suggestion_img','']],true);


		$data['module'] =$module;
		$data['types'] =$types;
		$data['suggestion'] =$suggestion;
		$data['suggestion_img'] =$suggestion_img;
		validate(HousingFeedbackSuggestionValidate::class)->check($data);

		try {
			Db::startTrans();
			$Model = new  \app\model\v1\housing\HousingFeedbackSuggestion();
			$person =  $Model->where ('user_id',$request->uid)->whereTime('ctime','today')->find ();
			if (!$person){
				$Model->insert ($data);
			}else{
				$result['status'] = false;
				$result['msg'] = '今天已经提交过建议';
				return json_encode($result);
			}
			Db::commit();
		} catch (\Exception $e) {
			Db::rollback();
			$result['msg'] = $e->getMessage();
			$result['status'] = false;
			return json_encode($result);
		}

		$result['status'] = true;
		$result['msg'] = '成功';
		return json_encode ($result);

	}


}
